[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
fstream File I/O Stream
The fstream class is used for file I/O in C++. It allows you
to use a file for both input and output. The fstream class is a
combination of both ifstream and ofstream. The important member
functions in fstream are:
istream &get(ch); Get one char from stream associated with object
char &ch; Location to put character at
ostream &put(ch); Put one char to stream associated with object
unsigned char *buf; Data buffer
int num; Number of bytes to read
istream &read(buf, num); Read num bytes from this object's stream
unsigned char *buf; Data buffer
int num; Number of bytes to read
ostream &write(buf, num); Write num bytes to this object's stream
unsigned char *buf; Data buffer
int num; Number of bytes to write
void open(filename, mode, access); Open a file.
char *filename; The file's name
int mode; Open mode:
in = 0x01 Open for reading
out = 0x02 Open for writing
ate = 0x04 Seek to eof upon open
app = 0x08 Append mode
trunc = 0x10 Truncate file if already exists
nocreate = 0x20 Open fails if doesn't exist
noreplace = 0x40 Open fails if already exists
binary = 0x80 Binary (not text) file
int access; Access:
0 = Normal file
1 = Read-only file
2 = Hidden file
4 = System file
8 = Archive bit set
void close(); Close file associated with this object (no parameters).
int eof(); Return nonzero value when the end of the file is reached.
istream &seekg(offset, origin); Move data get pointer
streamoff offset; Type defined in IOSTREAM.H
seek_dir origin; Seek_dir is an enumeration; possible values:
ios::beg = Beginning
ios::cur = Current location
ios::end = End
ostream &seekp(offset, origin); Move data put pointer
streamoff offset; Type defined in IOSTREAM.H
seek_dir origin; Seek_dir is an enumeration; possible values:
ios::beg = Beginning
ios::cur = Current location
ios::end = End
See Also:
ifstream
ofstream
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson